class FeedsController < ApplicationController

  def index
    if params[:id].blank?
      @feeds = []
    else
      @search = params[:id].gsub(/\s/, "%20").gsub(/#/, "")
      @twitter_feed = TwitterSearch::Client.new("kscope").query "##{@search}"
      @news_feed    = SimpleRSS.parse open("http://news.google.com/news?q=#{@search}&output=atom")
      
      @feeds = ( @twitter_feed.to_a + @news_feed.items ).map do |item|
        time = if item.respond_to?(:created_at)
          Time.parse(item.created_at)
        else
          item.modified
        end
        
        OpenStruct.new :item => item, :time => time
      end.sort_by(&:time).reverse
    end
  end

end
